import 'package:flutter/material.dart';

//类似android里的TextView可以draw个图片
class TextDrawWidget extends StatelessWidget {
  String data;
  String pic;
  Gravity drawGravity;
  double drawPadding;

  TextDrawWidget(this.data,
      {this.pic, this.drawGravity = Gravity.left, this.drawPadding = 0});

  @override
  Widget build(BuildContext context) {
    return Container(child: getWidget());
  }

  Widget getWidget() {
    var widget;
    switch (drawGravity) {
      case Gravity.left:
        widget = Row(
          children: <Widget>[
            Image.asset(pic),
            Container(padding : EdgeInsets.only(top: drawPadding),child: Text(data)),
          ],
        );

        break;
      case Gravity.top:
        widget = Column(
          children: <Widget>[
            Image.asset(pic),
            Container(padding : EdgeInsets.only(left: drawPadding),child: Text(data)),
          ],
        );
        break;
      case Gravity.right:
        widget = Row(
          children: <Widget>[
            Container(padding : EdgeInsets.only(bottom: drawPadding),child: Text(data)),
            Image.asset(pic),
          ],
        );
        break;
      case Gravity.bottom:
        widget = Column(
          children: <Widget>[
            Container(padding : EdgeInsets.only(right: drawPadding),child: Text(data)),
            Image.asset(pic),
          ],
        );
        break;
      default:
    }
    return widget;
  }
}

enum Gravity {
  left,
  top,
  bottom,
  right,
}
